﻿Imports System.Data.OracleClient
Imports System.IO
Imports System.Collections.Generic
Imports System.Web.Security
Imports System.Data

Public Class BSCSCampaignSMS
    'Inherits System.Web.UI.Page
    Inherits [lib].BasePage

    Dim DataEngine As New BSCSCampaignDefinition
    Protected Shared pgCount As Integer
    Protected Shared smsTextValue As New ArrayList
    Protected Shared smsTextValueEng As New ArrayList
    Protected Shared smsDayValue As New ArrayList
    Protected Shared smsConfirmRequestTextValue As New ArrayList
    Protected Shared screenConfirmRequestTextValue As New ArrayList
    Protected Shared smsConfirmCompleteTextValue As New ArrayList
    Protected Shared screenConfirmCompleteTextValue As New ArrayList

    Protected Shared smsId As String
    Protected Shared smsRadioButtonValue As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.PageTitle = "Kampanya SMS Bilgileri"
        Session("_CampaignSMSDefinition") = Nothing

        If (Not IsPostBack) Then
            ddlItemsToBeWorked.Items.Clear()
            ddlItemsToBeWorked.DataSource = DataEngine.GetSMSItemsToBeWorked()
            ddlItemsToBeWorked.DataBind()
            ddlItemsToBeWorked.Items.Insert(0, New ListItem("Seçiniz", "0"))
            ddlItemsToBeWorked.SelectedIndex = 0
        Else
            Dim eventTarget As String
            Dim eventArgument As String

            If (Me.Request("__EVENTTARGET") Is Nothing) Then
                eventTarget = String.Empty
            Else
                eventTarget = Me.Request("__EVENTTARGET")
                If (Me.Request("__EVENTARGUMENT") Is Nothing) Then
                    eventArgument = String.Empty
                Else
                    eventArgument = Me.Request("__EVENTARGUMENT")
                    If eventTarget = "openSmsPanel" Then
                        Dim valuePassed As String = eventArgument
                        Dim SearchString As String = valuePassed
                        Dim SearchChar As String = "-"
                        Dim SeperatorPos As Integer
                        Dim smsIndex As Integer
                        SeperatorPos = InStr(SearchString, SearchChar)
                        smsId = valuePassed.Substring(SeperatorPos)
                        smsIndex = valuePassed.Substring(0, SeperatorPos - 1)
                        smsRadioButtonValue = smsIndex
                        txtSmsDay.Text = smsDayValue.Item(smsIndex)
                        txtSmsText.Value = smsTextValue.Item(smsIndex)
                        myCounter.InnerText = txtSmsText.Value.Length

                        
                        If smsId = "hgAll" Then
                            lblSMSTitle.Text = "Tüm ücret grupları için girilmiş ortak Hoşgeldin SMS'i"
                        End If
                        If smsId = "thAll" Then
                            lblSMSTitle.Text = "Tüm ücret grupları için girilmiş ortak Taahhüt SMS'i"
                        End If
                        If smsId = "hgPG1" Then
                            lblSMSTitle.Text = "Ücret Grubu 1 için girilmiş Hoşgeldin SMS'i"
                        End If
                        If smsId = "thPG1" Then
                            lblSMSTitle.Text = "Ücret Grubu 1 için girilmiş Taahhüt SMS'i"
                        End If
                        If smsId = "hgPG2" Then
                            lblSMSTitle.Text = "Ücret Grubu 2 için girilmiş Hoşgeldin SMS'i"
                        End If
                        If smsId = "thPG2" Then
                            lblSMSTitle.Text = "Ücret Grubu 2 için girilmiş Taahhüt SMS'i"
                        End If
                        If smsId = "hgPG3" Then
                            lblSMSTitle.Text = "Ücret Grubu 3 için girilmiş Hoşgeldin SMS'i"
                        End If
                        If smsId = "thPG3" Then
                            lblSMSTitle.Text = "Ücret Grubu 3 için girilmiş Taahhüt SMS'i"
                        End If
                        If smsId = "hgPG4" Then
                            lblSMSTitle.Text = "Ücret Grubu 4 için girilmiş Hoşgeldin SMS'i"
                        End If
                        If smsId = "thPG4" Then
                            lblSMSTitle.Text = "Ücret Grubu 4 için girilmiş Taahhüt SMS'i"
                        End If
                        If smsId = "hgPG5" Then
                            lblSMSTitle.Text = "Ücret Grubu 5 için girilmiş Hoşgeldin SMS'i"
                        End If
                        If smsId = "thPG5" Then
                            lblSMSTitle.Text = "Ücret Grubu 5 için girilmiş Taahhüt SMS'i"
                        End If
                        If smsId = "hgPG6" Then
                            lblSMSTitle.Text = "Ücret Grubu 6 için girilmiş Hoşgeldin SMS'i"
                        End If
                        If smsId = "thPG6" Then
                            lblSMSTitle.Text = "Ücret Grubu 6 için girilmiş Taahhüt SMS'i"
                        End If

                        trSmsArea.Visible = True
                        divSaveSMSpanel.Visible = False
                        divDeleteSMSpanel.Visible = True
                        divConfirmDeletepanel.Visible = False
                        lblSMSStatus.Text = String.Empty

                        divEnglishSMSpanel.Visible = Not smsTextValueEng.Item(smsIndex).Equals(String.Empty)
                        If divEnglishSMSpanel.Visible Then
                            txtEnglishSmsText.Value = smsTextValueEng.Item(smsIndex)
                            myCounterEng.InnerText = txtEnglishSmsText.Value.Length
                        End If
                    ElseIf eventTarget = "openCommitmentDetailSmsPanel" Then
                        Dim valuePassed As String = eventArgument
                        Dim SearchString As String = valuePassed
                        Dim SearchChar As String = "-"
                        Dim SeperatorPos As Integer
                        Dim smsIndex As Integer
                        SeperatorPos = InStr(SearchString, SearchChar)
                        smsId = valuePassed.Substring(SeperatorPos)
                        smsIndex = valuePassed.Substring(0, SeperatorPos - 1)
                        smsRadioButtonValue = smsIndex
                        txtConfirmRequestSmsText.Value = smsConfirmRequestTextValue.Item(smsIndex)
                        txtConfirmRequestScreenText.Value = screenConfirmRequestTextValue.Item(smsIndex)
                        txtConfirmCompleteSmsText.Value = smsConfirmCompleteTextValue.Item(smsIndex)
                        txtConfirmCompleteScreenText.Value = screenConfirmCompleteTextValue.Item(smsIndex)

                        myCounterConfirmRequest.InnerText = txtConfirmRequestSmsText.Value.Length
                        myCounterConfirmRequestScreen.InnerText = txtConfirmRequestScreenText.Value.Length
                        myCounterConfirmComplete.InnerText = txtConfirmCompleteSmsText.Value.Length
                        myCounterConfirmCompleteScreen.InnerText = txtConfirmCompleteScreenText.Value.Length


                        If smsId = "thdAll" Then
                            lblSMSTitle.Text = "Tüm ücret grupları için girilmiş ortak Taahhüt Detay SMS'leri"
                        End If
                        If smsId = "thdPG1" Then
                            lblSMSTitle.Text = "Ücret Grubu 1 için girilmiş Taahhüt Detay SMS'leri"
                        End If
                        If smsId = "thdPG2" Then
                            lblSMSTitle.Text = "Ücret Grubu 2 için girilmiş Taahhüt Detay SMS'leri"
                        End If
                        If smsId = "thdPG3" Then
                            lblSMSTitle.Text = "Ücret Grubu 3 için girilmiş Taahhüt Detay SMS'leri"
                        End If
                        If smsId = "thdPG4" Then
                            lblSMSTitle.Text = "Ücret Grubu 4 için girilmiş Taahhüt Detay SMS'leri"
                        End If
                        If smsId = "thdPG5" Then
                            lblSMSTitle.Text = "Ücret Grubu 5 için girilmiş Taahhüt Detay SMS'leri"
                        End If
                        If smsId = "thdPG6" Then
                            lblSMSTitle.Text = "Ücret Grubu 6 için girilmiş Taahhüt Detay SMS'leri"
                        End If

                        trCommitmentDetailSmsArea.Visible = True
                        divSaveSMSpanelCommitmentDetail.Visible = False
                        divDeleteSMSpanelCommitmentDetail.Visible = True
                        divConfirmDeletepanelCommitmentDetail.Visible = False
                        lblCommitmentDetailSMSTitle.Text = String.Empty
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub EditSelection(ByVal pgId As Integer)

    End Sub

    Protected Sub ddlGeneralSMS_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlGeneralSMS.SelectedIndexChanged
        If ddlGeneralSMS.Items.Count = 3 Then
            ddlGeneralSMS.Items.RemoveAt(0)
        End If
        If ddlGeneralSMS.SelectedValue.Equals("Yes") Then
            trPGGeneralContent.Visible = True
            trPG1Content.Visible = False
            trPG2Content.Visible = False
            trPG3Content.Visible = False
            trPG4Content.Visible = False
            trPG5Content.Visible = False
            trPG6Content.Visible = False
        ElseIf (ddlGeneralSMS.SelectedValue.Equals("No")) Then
            trPGGeneralContent.Visible = False
            trPG1Content.Visible = True
            trPG2Content.Visible = (2 <= pgCount)
            trPG3Content.Visible = (3 <= pgCount)
            trPG4Content.Visible = (4 <= pgCount)
            trPG5Content.Visible = (5 <= pgCount)
            trPG6Content.Visible = (6 <= pgCount)
        End If

        trSmsArea.Visible = False
        lblSMSTitle.Text = String.Empty
        txtSmsDay.Text = String.Empty
        txtSmsText.Value = String.Empty
        divSaveSMSpanel.Visible = False
        divDeleteSMSpanel.Visible = False
        divConfirmDeletepanel.Visible = False
        rblWelcomePGGeneral.Items.Clear()
        rblCommitmentPGGeneral.Items.Clear()
        rblWelcomePG1.Items.Clear()
        rblCommitmentPG1.Items.Clear()
        rblWelcomePG2.Items.Clear()
        rblCommitmentPG2.Items.Clear()
        rblWelcomePG3.Items.Clear()
        rblCommitmentPG3.Items.Clear()
        rblWelcomePG4.Items.Clear()
        rblCommitmentPG4.Items.Clear()
        rblWelcomePG5.Items.Clear()
        rblCommitmentPG5.Items.Clear()
        rblWelcomePG6.Items.Clear()
        rblCommitmentPG6.Items.Clear()
        smsTextValue.Clear()
        smsDayValue.Clear()

        lblPGGeneralW.Visible = rblWelcomePGGeneral.Items.Count = 0
        lblPGGeneralC.Visible = rblCommitmentPGGeneral.Items.Count = 0
        lblPG1W.Visible = rblWelcomePG1.Items.Count = 0
        lblPG1C.Visible = rblCommitmentPG1.Items.Count = 0
        lblPG2W.Visible = rblWelcomePG2.Items.Count = 0
        lblPG2C.Visible = rblCommitmentPG2.Items.Count = 0
        lblPG3W.Visible = rblWelcomePG3.Items.Count = 0
        lblPG3C.Visible = rblCommitmentPG3.Items.Count = 0
        lblPG4W.Visible = rblWelcomePG4.Items.Count = 0
        lblPG4C.Visible = rblCommitmentPG4.Items.Count = 0
        lblPG5W.Visible = rblWelcomePG5.Items.Count = 0
        lblPG5C.Visible = rblCommitmentPG5.Items.Count = 0
        lblPG6W.Visible = rblWelcomePG6.Items.Count = 0
        lblPG6C.Visible = rblCommitmentPG6.Items.Count = 0
    End Sub

    Private Sub CommonJobForSmsSave(ByVal title As String, ByVal requestType As String)
        trSmsArea.Visible = True
        trCommitmentDetailSmsArea.Visible = False
        lblSMSTitle.Text = title
        txtSmsDay.Text = String.Empty
        txtSmsText.Value = String.Empty
        txtEnglishSmsText.Value = String.Empty
        myCounter.InnerText = 0
        divSaveSMSpanel.Visible = True
        divDeleteSMSpanel.Visible = False
        divConfirmDeletepanel.Visible = False
        cbEnglishSMSrequest.Visible = (requestType = "w")
        cbEnglishSMSrequest.Checked = False
        divEnglishSMSpanel.Visible = False

    End Sub
    Protected Sub lnkbtnWelcomeGeneral_Click(sender As Object, e As EventArgs) Handles lnkbtnWelcomeGeneral.Click
        smsId = "hgAll"
        CommonJobForSmsSave("Tüm ücret grupları için ortak Hoşgeldin SMS'i girişi", "w")
    End Sub

    Protected Sub lnkbtnCommitmentGeneral_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentGeneral.Click
        smsId = "thAll"
        CommonJobForSmsSave("Tüm ücret grupları için ortak Taahhüt SMS'i girişi", "c")
    End Sub

    Protected Sub lnkbtnWelcomePG1_Click(sender As Object, e As EventArgs) Handles lnkbtnWelcomePG1.Click
        smsId = "hgPG1"
        CommonJobForSmsSave("Ücret Grubu 1 için Hoşgeldin SMS'i girişi", "w")
    End Sub

    Protected Sub lnkbtnCommitmentPG1_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentPG1.Click
        smsId = "thPG1"
        CommonJobForSmsSave("Ücret Grubu 1 için Taahhüt SMS'i girişi", "c")
    End Sub

    Protected Sub lnkbtnWelcomePG2_Click(sender As Object, e As EventArgs) Handles lnkbtnWelcomePG2.Click
        smsId = "hgPG2"
        CommonJobForSmsSave("Ücret Grubu 2 için Hoşgeldin SMS'i girişi", "w")
    End Sub

    Protected Sub lnkbtnCommitmentPG2_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentPG2.Click
        smsId = "thPG2"
        CommonJobForSmsSave("Ücret Grubu 2 için Taahhüt SMS'i girişi", "c")
    End Sub

    Protected Sub lnkbtnWelcomePG3_Click(sender As Object, e As EventArgs) Handles lnkbtnWelcomePG3.Click
        smsId = "hgPG3"
        CommonJobForSmsSave("Ücret Grubu 3 için Hoşgeldin SMS'i girişi", "w")
    End Sub

    Protected Sub lnkbtnCommitmentPG3_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentPG3.Click
        smsId = "thPG3"
        CommonJobForSmsSave("Ücret Grubu 3 için Taahhüt SMS'i girişi", "c")
    End Sub

    Protected Sub lnkbtnWelcomePG4_Click(sender As Object, e As EventArgs) Handles lnkbtnWelcomePG4.Click
        smsId = "hgPG4"
        CommonJobForSmsSave("Ücret Grubu 4 için Hoşgeldin SMS'i girişi", "w")
    End Sub

    Protected Sub lnkbtnCommitmentPG4_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentPG4.Click
        smsId = "thPG4"
        CommonJobForSmsSave("Ücret Grubu 4 için Taahhüt SMS'i girişi", "c")
    End Sub

    Protected Sub lnkbtnWelcomePG5_Click(sender As Object, e As EventArgs) Handles lnkbtnWelcomePG5.Click
        smsId = "hgPG5"
        CommonJobForSmsSave("Ücret Grubu 5 için Hoşgeldin SMS'i girişi", "w")
    End Sub

    Protected Sub lnkbtnCommitmentPG5_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentPG5.Click
        smsId = "thPG5"
        CommonJobForSmsSave("Ücret Grubu 5 için Taahhüt SMS'i girişi", "c")
    End Sub

    Protected Sub lnkbtnWelcomePG6_Click(sender As Object, e As EventArgs) Handles lnkbtnWelcomePG6.Click
        smsId = "hgPG6"
        CommonJobForSmsSave("Ücret Grubu 6 için Hoşgeldin SMS'i girişi", "w")
    End Sub

    Protected Sub lnkbtnCommitmentPG6_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentPG6.Click
        smsId = "thPG6"
        CommonJobForSmsSave("Ücret Grubu 6 için Taahhüt SMS'i girişi", "c")
    End Sub

    Protected Sub btnCheckTurkishChars_Click(sender As Object, e As EventArgs) Handles btnCheckTurkishChars.Click
        Dim hasTurkishChar As Boolean = False
        Dim txtSmsValue As String = txtSmsText.Value

        myCounter.InnerText = txtSmsText.Value.Length

        myCounterEng.InnerText = txtEnglishSmsText.Value.Length

        If txtSmsValue.Length = 0 Then
            lblSMSStatus.Text = String.Empty
            Return
        End If


        hasTurkishChar = txtSmsText.Value.Contains("ı") Or _
            txtSmsText.Value.Contains("ü") Or _
            txtSmsText.Value.Contains("ö") Or _
            txtSmsText.Value.Contains("ş") Or _
            txtSmsText.Value.Contains("ç") Or _
            txtSmsText.Value.Contains("ğ") Or _
            txtSmsText.Value.Contains("İ") Or _
            txtSmsText.Value.Contains("Ü") Or _
            txtSmsText.Value.Contains("Ö") Or _
            txtSmsText.Value.Contains("Ş") Or _
            txtSmsText.Value.Contains("Ç") Or _
            txtSmsText.Value.Contains("Ğ")

        If hasTurkishChar Then
            lblSMSStatus.Text = "Türkçe karakterler düzeltildi."
            txtSmsText.Value = txtSmsText.Value.Replace("ı", "i")
            txtSmsText.Value = txtSmsText.Value.Replace("ü", "u")
            txtSmsText.Value = txtSmsText.Value.Replace("ö", "o")
            txtSmsText.Value = txtSmsText.Value.Replace("ş", "s")
            txtSmsText.Value = txtSmsText.Value.Replace("ç", "c")
            txtSmsText.Value = txtSmsText.Value.Replace("ğ", "g")
            txtSmsText.Value = txtSmsText.Value.Replace("İ", "I")
            txtSmsText.Value = txtSmsText.Value.Replace("Ü", "U")
            txtSmsText.Value = txtSmsText.Value.Replace("Ö", "O")
            txtSmsText.Value = txtSmsText.Value.Replace("Ş", "S")
            txtSmsText.Value = txtSmsText.Value.Replace("Ç", "C")
            txtSmsText.Value = txtSmsText.Value.Replace("Ğ", "G")
        Else
            lblSMSStatus.Text = "SMS metninde Türkçe karakter bulunmamaktadır."
        End If
        
    End Sub

    Private Function CheckIf1stDaySMSExist(ByVal rbl As RadioButtonList) As Boolean
        Dim index As Integer
        Dim SearchString As String
        Dim SearchChars As String
        Dim Seperator1Pos As Integer
        Dim Seperator2Pos As Integer
        Dim dayIndex As Integer

        index = 0
        While index < rbl.Items.Count
            SearchChars = ">"
            SearchString = rbl.Items(index).Text
            Seperator1Pos = InStr(SearchString, SearchChars)
            SearchChars = "."
            Seperator2Pos = InStr(SearchString, SearchChars)
            dayIndex = SearchString.Substring(Seperator1Pos, Seperator2Pos - Seperator1Pos)
            If dayIndex = "1" Then
                lblSMSStatus.Text = "Sadece 1 adet 1. gün SMS'i girilebilir."
                Return False
            End If
            index += 1
        End While
        Return True
    End Function

    Protected Sub btnSaveSMS_Click(sender As Object, e As EventArgs) Handles btnSaveSMS.Click
        Dim checkSMSdata As Boolean = True

        myCounter.InnerText = txtSmsText.Value.Length
        myCounterEng.InnerText = txtEnglishSmsText.Value.Length

        If (txtSmsText.Value.Length = 0) Then
            checkSMSdata = False
            lblSMSStatus.Text = "SMS metni girilmedi. SMS metnini girdikten sonra kaydetmeyi deneyiniz."
        Else
            If divEnglishSMSpanel.Visible Then
                checkSMSdata = (txtEnglishSmsText.Value.Length > 0)
                If Not checkSMSdata Then
                    lblSMSStatus.Text = "İngilizce SMS metni girilmedi. İngilizce SMS metnini girdikten sonra kaydetmeyi deneyiniz."
                End If
            End If
        End If
        If Not checkSMSdata Then
            Return
        End If

        If txtSmsDay.Text = String.Empty Then
            checkSMSdata = False
            lblSMSStatus.Text = "SMS'in gönderileceği gün bilgisi girilmedi. Gün bilgisini girdikten sonra kaydetmeyi deneyiniz."
        Else
            If txtSmsDay.Text = "1" Then
                If smsId = "hgAll" Then
                    checkSMSdata = CheckIf1stDaySMSExist(rblWelcomePGGeneral)
                End If
                If smsId = "thAll" Then
                    checkSMSdata = False
                    lblSMSStatus.Text = "Taahhüt SMS'leri 1. gün gönderilemez."
                End If
                If smsId = "hgPG1" Then
                    checkSMSdata = CheckIf1stDaySMSExist(rblWelcomePG1)
                End If
                If smsId = "thPG1" Then
                    checkSMSdata = False
                    lblSMSStatus.Text = "Taahhüt SMS'leri 1. gün gönderilemez."
                End If
                If smsId = "hgPG2" Then
                    checkSMSdata = CheckIf1stDaySMSExist(rblWelcomePG2)
                End If
                If smsId = "thPG2" Then
                    checkSMSdata = False
                    lblSMSStatus.Text = "Taahhüt SMS'leri 1. gün gönderilemez."
                End If
                If smsId = "hgPG3" Then
                    checkSMSdata = CheckIf1stDaySMSExist(rblWelcomePG3)
                End If
                If smsId = "thPG3" Then
                    checkSMSdata = False
                    lblSMSStatus.Text = "Taahhüt SMS'leri 1. gün gönderilemez."
                End If
                If smsId = "hgPG4" Then
                    checkSMSdata = CheckIf1stDaySMSExist(rblWelcomePG4)
                End If
                If smsId = "thPG4" Then
                    checkSMSdata = False
                    lblSMSStatus.Text = "Taahhüt SMS'leri 1. gün gönderilemez."
                End If
                If smsId = "hgPG5" Then
                    checkSMSdata = CheckIf1stDaySMSExist(rblWelcomePG5)
                End If
                If smsId = "thPG5" Then
                    checkSMSdata = False
                    lblSMSStatus.Text = "Taahhüt SMS'leri 1. gün gönderilemez."
                End If
                If smsId = "hgPG6" Then
                    checkSMSdata = CheckIf1stDaySMSExist(rblWelcomePG6)
                End If
                If smsId = "thPG6" Then
                    checkSMSdata = False
                    lblSMSStatus.Text = "Taahhüt SMS'leri 1. gün gönderilemez."
                End If
            End If
        End If
        If checkSMSdata Then

            Dim li As New ListItem

            smsTextValue.Add(txtSmsText.Value)
            If divEnglishSMSpanel.Visible Then
                smsTextValueEng.Add(txtEnglishSmsText.Value)
            Else
                smsTextValueEng.Add(String.Empty)
            End If
            smsDayValue.Add(txtSmsDay.Text)
            li.Value = smsTextValue.Count - 1

            li.Text = "<a href=# onclick=""showSmsPanel('openSmsPanel','" & li.Value & "-" & smsId & "')"">" & txtSmsDay.Text & ". gun atilacak SMS</a>"

            If smsId = "hgAll" Then
                rblWelcomePGGeneral.Items.Add(li)
            End If
            If smsId = "thAll" Then
                rblCommitmentPGGeneral.Items.Add(li)
            End If
            If smsId = "hgPG1" Then
                rblWelcomePG1.Items.Add(li)
            End If
            If smsId = "thPG1" Then
                rblCommitmentPG1.Items.Add(li)
            End If
            If smsId = "hgPG2" Then
                rblWelcomePG2.Items.Add(li)
            End If
            If smsId = "thPG2" Then
                rblCommitmentPG2.Items.Add(li)
            End If
            If smsId = "hgPG3" Then
                rblWelcomePG3.Items.Add(li)
            End If
            If smsId = "thPG3" Then
                rblCommitmentPG3.Items.Add(li)
            End If
            If smsId = "hgPG4" Then
                rblWelcomePG4.Items.Add(li)
            End If
            If smsId = "thPG4" Then
                rblCommitmentPG4.Items.Add(li)
            End If
            If smsId = "hgPG5" Then
                rblWelcomePG5.Items.Add(li)
            End If
            If smsId = "thPG5" Then
                rblCommitmentPG5.Items.Add(li)
            End If
            If smsId = "hgPG6" Then
                rblWelcomePG6.Items.Add(li)
            End If
            If smsId = "thPG6" Then
                rblCommitmentPG6.Items.Add(li)
            End If

            trSmsArea.Visible = False
            lblSMSTitle.Text = String.Empty
            lblSMSStatus.Text = String.Empty
            txtSmsDay.Text = String.Empty
            txtSmsText.Value = String.Empty
            divSaveSMSpanel.Visible = False
            divDeleteSMSpanel.Visible = False
            divConfirmDeletepanel.Visible = False
        Else
            Return
        End If

        lblPGGeneralW.Visible = rblWelcomePGGeneral.Items.Count = 0
        lblPGGeneralC.Visible = rblCommitmentPGGeneral.Items.Count = 0
        lblPG1W.Visible = rblWelcomePG1.Items.Count = 0
        lblPG1C.Visible = rblCommitmentPG1.Items.Count = 0
        lblPG2W.Visible = rblWelcomePG2.Items.Count = 0
        lblPG2C.Visible = rblCommitmentPG2.Items.Count = 0
        lblPG3W.Visible = rblWelcomePG3.Items.Count = 0
        lblPG3C.Visible = rblCommitmentPG3.Items.Count = 0
        lblPG4W.Visible = rblWelcomePG4.Items.Count = 0
        lblPG4C.Visible = rblCommitmentPG4.Items.Count = 0
        lblPG5W.Visible = rblWelcomePG5.Items.Count = 0
        lblPG5C.Visible = rblCommitmentPG5.Items.Count = 0
        lblPG6W.Visible = rblWelcomePG6.Items.Count = 0
        lblPG6C.Visible = rblCommitmentPG6.Items.Count = 0
    End Sub

    Protected Sub btnCancelSave_Click(sender As Object, e As EventArgs) Handles btnCancelSave.Click
        trSmsArea.Visible = False
        lblSMSTitle.Text = String.Empty
        txtSmsDay.Text = String.Empty
        txtSmsText.Value = String.Empty
        divSaveSMSpanel.Visible = False
        divDeleteSMSpanel.Visible = False
        divConfirmDeletepanel.Visible = False
    End Sub

    Protected Sub btnCancel2_Click(sender As Object, e As EventArgs) Handles btnCancel2.Click
        trSmsArea.Visible = False
        lblSMSTitle.Text = String.Empty
        txtSmsDay.Text = String.Empty
        txtSmsText.Value = String.Empty
        divSaveSMSpanel.Visible = False
        divDeleteSMSpanel.Visible = False
        divConfirmDeletepanel.Visible = False
    End Sub

    Protected Sub btnDeleteSMS_Click(sender As Object, e As EventArgs) Handles btnDeleteSMS.Click
        divSaveSMSpanel.Visible = False
        divDeleteSMSpanel.Visible = False
        divConfirmDeletepanel.Visible = True
    End Sub

    Protected Sub btnCancelDelete_Click(sender As Object, e As EventArgs) Handles btnCancelDelete.Click
        trSmsArea.Visible = False
        lblSMSTitle.Text = String.Empty
        txtSmsDay.Text = String.Empty
        txtSmsText.Value = String.Empty
        divSaveSMSpanel.Visible = False
        divDeleteSMSpanel.Visible = False
        divConfirmDeletepanel.Visible = False
    End Sub

    Private Sub removeItemFromRadioButtonList(ByVal rbl As RadioButtonList)
        Dim indexToDelete As Integer
        indexToDelete = rbl.Items.IndexOf(rbl.Items.FindByValue(smsRadioButtonValue.ToString))
        rbl.Items.RemoveAt(indexToDelete)
    End Sub

    Protected Sub btnConfirmDelete_Click(sender As Object, e As EventArgs) Handles btnConfirmDelete.Click
        If smsId = "hgAll" Then
            removeItemFromRadioButtonList(rblWelcomePGGeneral)
        End If
        If smsId = "thAll" Then
            removeItemFromRadioButtonList(rblCommitmentPGGeneral)
        End If
        If smsId = "hgPG1" Then
            removeItemFromRadioButtonList(rblWelcomePG1)
        End If
        If smsId = "thPG1" Then
            removeItemFromRadioButtonList(rblCommitmentPG1)
        End If
        If smsId = "hgPG2" Then
            removeItemFromRadioButtonList(rblWelcomePG2)
        End If
        If smsId = "thPG2" Then
            removeItemFromRadioButtonList(rblCommitmentPG2)
        End If
        If smsId = "hgPG3" Then
            removeItemFromRadioButtonList(rblWelcomePG3)
        End If
        If smsId = "thPG3" Then
            removeItemFromRadioButtonList(rblCommitmentPG3)
        End If
        If smsId = "hgPG4" Then
            removeItemFromRadioButtonList(rblWelcomePG4)
        End If
        If smsId = "thPG4" Then
            removeItemFromRadioButtonList(rblCommitmentPG4)
        End If
        If smsId = "hgPG5" Then
            removeItemFromRadioButtonList(rblWelcomePG5)
        End If
        If smsId = "thPG5" Then
            removeItemFromRadioButtonList(rblCommitmentPG5)
        End If
        If smsId = "hgPG6" Then
            removeItemFromRadioButtonList(rblWelcomePG6)
        End If
        If smsId = "thPG6" Then
            removeItemFromRadioButtonList(rblCommitmentPG6)
        End If

        trSmsArea.Visible = False
        lblSMSTitle.Text = String.Empty
        txtSmsDay.Text = String.Empty
        txtSmsText.Value = String.Empty
        divSaveSMSpanel.Visible = False
        divDeleteSMSpanel.Visible = False
        divConfirmDeletepanel.Visible = False

        lblPGGeneralW.Visible = rblWelcomePGGeneral.Items.Count = 0
        lblPGGeneralC.Visible = rblCommitmentPGGeneral.Items.Count = 0
        lblPG1W.Visible = rblWelcomePG1.Items.Count = 0
        lblPG1C.Visible = rblCommitmentPG1.Items.Count = 0
        lblPG2W.Visible = rblWelcomePG2.Items.Count = 0
        lblPG2C.Visible = rblCommitmentPG2.Items.Count = 0
        lblPG3W.Visible = rblWelcomePG3.Items.Count = 0
        lblPG3C.Visible = rblCommitmentPG3.Items.Count = 0
        lblPG4W.Visible = rblWelcomePG4.Items.Count = 0
        lblPG4C.Visible = rblCommitmentPG4.Items.Count = 0
        lblPG5W.Visible = rblWelcomePG5.Items.Count = 0
        lblPG5C.Visible = rblCommitmentPG5.Items.Count = 0
        lblPG6W.Visible = rblWelcomePG6.Items.Count = 0
        lblPG6C.Visible = rblCommitmentPG6.Items.Count = 0
    End Sub

    Private Sub BuildListBoxesForAllPriceGroups(ByVal temp_tariff_id As Integer)

        pgCount = DataEngine.GetPriceGroupCountForTariff(temp_tariff_id)

        Dim dt As DataTable

        lbPG1reasons.Items.Clear()
        lbPG2reasons.Items.Clear()
        lbPG3reasons.Items.Clear()
        lbPG4reasons.Items.Clear()
        lbPG5reasons.Items.Clear()
        lbPG6reasons.Items.Clear()

        For index As Integer = 1 To pgCount
            dt = DataEngine.GetPriceGroupReasonsOfTariff(temp_tariff_id, index)

            For Each row As DataRow In dt.Rows
                If row("root") = "0" Then
                    Dim isThereAnyChild As Boolean = False

                    For Each row2 As DataRow In dt.Rows
                        If row2("root").Equals(row("value")) Then
                            isThereAnyChild = True
                        End If
                    Next row2

                    If isThereAnyChild Then
                        Dim newItem As New ListItem

                        newItem.Text = row("text")
                        newItem.Value = row("value")
                        If index = 1 Then
                            lbPG1reasons.Items.Add(newItem)
                        ElseIf index = 2 Then
                            lbPG2reasons.Items.Add(newItem)
                        ElseIf index = 3 Then
                            lbPG3reasons.Items.Add(newItem)
                        ElseIf index = 4 Then
                            lbPG4reasons.Items.Add(newItem)
                        ElseIf index = 5 Then
                            lbPG5reasons.Items.Add(newItem)
                        ElseIf index = 6 Then
                            lbPG6reasons.Items.Add(newItem)
                        End If

                        For Each row2 As DataRow In dt.Rows
                            If row2("root") = row("value") Then
                                Dim newChildItem As New ListItem

                                newChildItem.Text = "• " & row2("text")
                                newChildItem.Value = row2("value")
                                If index = 1 Then
                                    lbPG1reasons.Items.Add(newChildItem)
                                ElseIf index = 2 Then
                                    lbPG2reasons.Items.Add(newChildItem)
                                ElseIf index = 3 Then
                                    lbPG3reasons.Items.Add(newChildItem)
                                ElseIf index = 4 Then
                                    lbPG4reasons.Items.Add(newChildItem)
                                ElseIf index = 5 Then
                                    lbPG5reasons.Items.Add(newChildItem)
                                ElseIf index = 6 Then
                                    lbPG6reasons.Items.Add(newChildItem)
                                End If
                            End If
                        Next row2
                    End If
                End If
            Next row
        Next index

        dt = DataEngine.GetPriceGroupFeeDetailsOfTariff(temp_tariff_id)
        Dim basePrice As Double = 0
        Dim commitment_status As Boolean = True
        For Each row As DataRow In dt.Rows
            If row("value") = 1 Then
                lblTariffNormalPricePG1.Text = "Aylık Sabit Ücret (Vergi dahil): " & row("text") & " TL"
                If row("cmf") = "-1" Then
                    lblTariffNormalPricePG1withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): N/A"
                    divCommitment1.Visible = False
                    divCommitmentDetail1.Visible = False
                    commitment_status = False
                Else
                    lblTariffNormalPricePG1withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): " & row("cmf") & " TL"
                    divCommitment1.Visible = True
                    divCommitmentDetail1.Visible = True
                End If
                If CDbl(row("text")) > basePrice Then
                    basePrice = CDbl(row("text"))
                End If
            ElseIf row("value") = 2 Then
                lblTariffNormalPricePG2.Text = "Aylık Sabit Ücret (Vergi dahil): " & row("text") & " TL"
                If row("cmf") = "-1" Then
                    lblTariffNormalPricePG2withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): N/A"
                    divCommitment2.Visible = False
                    divCommitmentDetail2.Visible = False
                Else
                    lblTariffNormalPricePG2withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): " & row("cmf") & " TL"
                    divCommitment2.Visible = True
                    divCommitmentDetail2.Visible = True
                End If
                If CDbl(row("text")) > basePrice Then
                    basePrice = CDbl(row("text"))
                End If
            ElseIf row("value") = 3 Then
                lblTariffNormalPricePG3.Text = "Aylık Sabit Ücret (Vergi dahil): " & row("text") & " TL"
                If row("cmf") = "-1" Then
                    lblTariffNormalPricePG3withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): N/A"
                    divCommitment3.Visible = False
                    divCommitmentDetail3.Visible = False
                Else
                    lblTariffNormalPricePG3withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): " & row("cmf") & " TL"
                    divCommitment3.Visible = True
                    divCommitmentDetail3.Visible = True
                End If
                If CDbl(row("text")) > basePrice Then
                    basePrice = CDbl(row("text"))
                End If
            ElseIf row("value") = 4 Then
                lblTariffNormalPricePG4.Text = "Aylık Sabit Ücret (Vergi dahil): " & row("text") & " TL"
                If row("cmf") = "-1" Then
                    lblTariffNormalPricePG4withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): N/A"
                    divCommitment4.Visible = False
                    divCommitmentDetail4.Visible = False
                Else
                    lblTariffNormalPricePG4withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): " & row("cmf") & " TL"
                    divCommitment4.Visible = True
                    divCommitmentDetail4.Visible = True
                End If
                If CDbl(row("text")) > basePrice Then
                    basePrice = CDbl(row("text"))
                End If
            ElseIf row("value") = 5 Then
                lblTariffNormalPricePG5.Text = "Aylık Sabit Ücret (Vergi dahil): " & row("text") & " TL"
                If row("cmf") = "-1" Then
                    lblTariffNormalPricePG5withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): N/A"
                    divCommitment5.Visible = False
                    divCommitmentDetail5.Visible = False
                Else
                    lblTariffNormalPricePG5withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): " & row("cmf") & " TL"
                    divCommitment5.Visible = True
                    divCommitmentDetail5.Visible = True
                End If
                If CDbl(row("text")) > basePrice Then
                    basePrice = CDbl(row("text"))
                End If
            ElseIf row("value") = 6 Then
                If CDbl(row("text")) > basePrice Then
                    lblTariffNormalPricePG6.Text = "Aylık Sabit Ücret (Vergi dahil): " & row("text") & " TL"
                    If row("cmf") = "-1" Then
                        lblTariffNormalPricePG6withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): N/A"
                        divCommitment6.Visible = False
                        divCommitmentDetail6.Visible = False
                    Else
                        lblTariffNormalPricePG6withCommitment.Text = "Taahhütlü Aylık Sabit Ücret (Vergi dahil): " & row("cmf") & " TL"
                        divCommitment6.Visible = True
                        divCommitmentDetail6.Visible = True
                    End If
                    If CDbl(row("text")) > basePrice Then
                        basePrice = CDbl(row("text"))
                    End If
                End If
            End If
        Next row
        lblTariffBasePrice.Text = "Tarife Ücreti (Vergi dahil): " & basePrice & " TL"
        divCommitmentGeneral.Visible = commitment_status
        divCommitmentDetailGeneral.Visible = commitment_status

    End Sub

    Protected Sub ddlItemsToBeWorked_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlItemsToBeWorked.SelectedIndexChanged
        WorkingItems.Visible = False
        WorkingItem.Visible = True
        SMSConfigurationStep1.Visible = True
        lblWorkingItem.Text = "Geçici ID'si: " & ddlItemsToBeWorked.Text & " olan tarife için SMS girişleri"
        BuildListBoxesForAllPriceGroups(ddlItemsToBeWorked.SelectedValue)
    End Sub

    Protected Sub cbEnglishSMSrequest_CheckedChanged(sender As Object, e As EventArgs) Handles cbEnglishSMSrequest.CheckedChanged
        divEnglishSMSpanel.Visible = cbEnglishSMSrequest.Checked
        txtEnglishSmsText.Value = String.Empty
        myCounterEng.InnerText = 0
    End Sub

    Private Sub CommonJobForSmsSaveCommitmentDetail(ByVal title As String)
        trSmsArea.Visible = False
        trCommitmentDetailSmsArea.Visible = True
        lblCommitmentDetailSMSTitle.Text = title
        txtConfirmRequestSmsText.Value = String.Empty
        txtConfirmRequestScreenText.Value = String.Empty
        txtConfirmCompleteSmsText.Value = String.Empty
        txtConfirmCompleteScreenText.Value = String.Empty
        myCounterConfirmRequest.InnerText = 0
        myCounterConfirmComplete.InnerText = 0
        myCounterConfirmRequestScreen.InnerText = 0
        myCounterConfirmCompleteScreen.InnerText = 0
        divSaveSMSpanelCommitmentDetail.Visible = True
        divDeleteSMSpanelCommitmentDetail.Visible = False
        divConfirmDeletepanelCommitmentDetail.Visible = False
    End Sub

    Protected Sub lnkbtnCommitmentDetailGeneral_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentDetailGeneral.Click
        smsId = "thdAll"
        CommonJobForSmsSaveCommitmentDetail("Tüm ücret grupları için ortak Taahhüt Detay SMS'leri girişi")
    End Sub

    Protected Sub lnkbtnCommitmentDetailPG1_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentDetailPG1.Click
        smsId = "thdPG1"
        CommonJobForSmsSaveCommitmentDetail("Ücret Grubu 1 için Taahhüt Detay SMS'leri girişi")
    End Sub

    Protected Sub lnkbtnCommitmentDetailPG2_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentDetailPG2.Click
        smsId = "thdPG2"
        CommonJobForSmsSaveCommitmentDetail("Ücret Grubu 2 için Taahhüt Detay SMS'leri girişi")
    End Sub

    Protected Sub lnkbtnCommitmentDetailPG3_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentDetailPG3.Click
        smsId = "thdPG3"
        CommonJobForSmsSaveCommitmentDetail("Ücret Grubu 3 için Taahhüt Detay SMS'leri girişi")
    End Sub

    Protected Sub lnkbtnCommitmentDetailPG4_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentDetailPG4.Click
        smsId = "thdPG4"
        CommonJobForSmsSaveCommitmentDetail("Ücret Grubu 4 için Taahhüt Detay SMS'leri girişi")
    End Sub

    Protected Sub lnkbtnCommitmentDetailPG5_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentDetailPG5.Click
        smsId = "thdPG5"
        CommonJobForSmsSaveCommitmentDetail("Ücret Grubu 5 için Taahhüt Detay SMS'leri girişi")
    End Sub

    Protected Sub lnkbtnCommitmentDetailPG6_Click(sender As Object, e As EventArgs) Handles lnkbtnCommitmentDetailPG6.Click
        smsId = "thdPG6"
        CommonJobForSmsSaveCommitmentDetail("Ücret Grubu 6 için Taahhüt Detay SMS'leri girişi")
    End Sub

    Protected Sub btnCheckTurkishCharsCommitmentDetail_Click(sender As Object, e As EventArgs) Handles btnCheckTurkishCharsCommitmentDetail.Click
        Dim hasTurkishChar As Boolean = False

        myCounterConfirmRequest.InnerText = txtConfirmRequestSmsText.Value.Length
        myCounterConfirmRequestScreen.InnerText = txtConfirmRequestScreenText.Value.Length
        myCounterConfirmComplete.InnerText = txtConfirmCompleteSmsText.Value.Length
        myCounterConfirmCompleteScreen.InnerText = txtConfirmCompleteScreenText.Value.Length

        hasTurkishChar = txtConfirmRequestSmsText.Value.Contains("ı") Or _
            txtConfirmRequestSmsText.Value.Contains("ü") Or _
            txtConfirmRequestSmsText.Value.Contains("ö") Or _
            txtConfirmRequestSmsText.Value.Contains("ş") Or _
            txtConfirmRequestSmsText.Value.Contains("ç") Or _
            txtConfirmRequestSmsText.Value.Contains("ğ") Or _
            txtConfirmRequestSmsText.Value.Contains("İ") Or _
            txtConfirmRequestSmsText.Value.Contains("Ü") Or _
            txtConfirmRequestSmsText.Value.Contains("Ö") Or _
            txtConfirmRequestSmsText.Value.Contains("Ş") Or _
            txtConfirmRequestSmsText.Value.Contains("Ç") Or _
            txtConfirmRequestSmsText.Value.Contains("Ğ") Or _
            txtConfirmRequestScreenText.Value.Contains("ı") Or _
            txtConfirmRequestScreenText.Value.Contains("ü") Or _
            txtConfirmRequestScreenText.Value.Contains("ö") Or _
            txtConfirmRequestScreenText.Value.Contains("ş") Or _
            txtConfirmRequestScreenText.Value.Contains("ç") Or _
            txtConfirmRequestScreenText.Value.Contains("ğ") Or _
            txtConfirmRequestScreenText.Value.Contains("İ") Or _
            txtConfirmRequestScreenText.Value.Contains("Ü") Or _
            txtConfirmRequestScreenText.Value.Contains("Ö") Or _
            txtConfirmRequestScreenText.Value.Contains("Ş") Or _
            txtConfirmRequestScreenText.Value.Contains("Ç") Or _
            txtConfirmRequestScreenText.Value.Contains("Ğ") Or _
            txtConfirmCompleteSmsText.Value.Contains("ı") Or _
            txtConfirmCompleteSmsText.Value.Contains("ü") Or _
            txtConfirmCompleteSmsText.Value.Contains("ö") Or _
            txtConfirmCompleteSmsText.Value.Contains("ş") Or _
            txtConfirmCompleteSmsText.Value.Contains("ç") Or _
            txtConfirmCompleteSmsText.Value.Contains("ğ") Or _
            txtConfirmCompleteSmsText.Value.Contains("İ") Or _
            txtConfirmCompleteSmsText.Value.Contains("Ü") Or _
            txtConfirmCompleteSmsText.Value.Contains("Ö") Or _
            txtConfirmCompleteSmsText.Value.Contains("Ş") Or _
            txtConfirmCompleteSmsText.Value.Contains("Ç") Or _
            txtConfirmCompleteSmsText.Value.Contains("Ğ") Or _
            txtConfirmCompleteScreenText.Value.Contains("ı") Or _
            txtConfirmCompleteScreenText.Value.Contains("ü") Or _
            txtConfirmCompleteScreenText.Value.Contains("ö") Or _
            txtConfirmCompleteScreenText.Value.Contains("ş") Or _
            txtConfirmCompleteScreenText.Value.Contains("ç") Or _
            txtConfirmCompleteScreenText.Value.Contains("ğ") Or _
            txtConfirmCompleteScreenText.Value.Contains("İ") Or _
            txtConfirmCompleteScreenText.Value.Contains("Ü") Or _
            txtConfirmCompleteScreenText.Value.Contains("Ö") Or _
            txtConfirmCompleteScreenText.Value.Contains("Ş") Or _
            txtConfirmCompleteScreenText.Value.Contains("Ç") Or _
            txtConfirmCompleteScreenText.Value.Contains("Ğ")

        If hasTurkishChar Then
            lblSMSStatusCommitmentDetail.Text = "Türkçe karakterler düzeltildi."
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("ı", "i")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("ü", "u")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("ö", "o")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("ş", "s")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("ç", "c")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("ğ", "g")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("İ", "I")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("Ü", "U")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("Ö", "O")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("Ş", "S")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("Ç", "C")
            txtConfirmRequestSmsText.Value = txtConfirmRequestSmsText.Value.Replace("Ğ", "G")

            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("ı", "i")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("ü", "u")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("ö", "o")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("ş", "s")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("ç", "c")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("ğ", "g")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("İ", "I")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("Ü", "U")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("Ö", "O")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("Ş", "S")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("Ç", "C")
            txtConfirmRequestScreenText.Value = txtConfirmRequestScreenText.Value.Replace("Ğ", "G")

            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("ı", "i")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("ü", "u")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("ö", "o")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("ş", "s")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("ç", "c")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("ğ", "g")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("İ", "I")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("Ü", "U")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("Ö", "O")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("Ş", "S")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("Ç", "C")
            txtConfirmCompleteSmsText.Value = txtConfirmCompleteSmsText.Value.Replace("Ğ", "G")

            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("ı", "i")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("ü", "u")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("ö", "o")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("ş", "s")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("ç", "c")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("ğ", "g")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("İ", "I")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("Ü", "U")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("Ö", "O")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("Ş", "S")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("Ç", "C")
            txtConfirmCompleteScreenText.Value = txtConfirmCompleteScreenText.Value.Replace("Ğ", "G")
        Else
            lblSMSStatusCommitmentDetail.Text = "SMS metninde Türkçe karakter bulunmamaktadır."
        End If
    End Sub

    Protected Sub btnSaveSMSCommitmentDetail_Click(sender As Object, e As EventArgs) Handles btnSaveSMSCommitmentDetail.Click
        Dim checkSMSdata As Boolean = True

        myCounterConfirmRequest.InnerText = txtConfirmRequestSmsText.Value.Length
        myCounterConfirmRequestScreen.InnerText = txtConfirmRequestScreenText.Value.Length
        myCounterConfirmComplete.InnerText = txtConfirmCompleteSmsText.Value.Length
        myCounterConfirmCompleteScreen.InnerText = txtConfirmCompleteScreenText.Value.Length

        If (txtConfirmRequestSmsText.Value.Length = 0) Then
            checkSMSdata = False
            lblSMSStatusCommitmentDetail.Text = "Onay İsteme SMS metni girilmedi. Onay İsteme SMS metnini girdikten sonra kaydetmeyi deneyiniz."
            Return
        End If

        If (txtConfirmRequestScreenText.Value.Length = 0) Then
            checkSMSdata = False
            lblSMSStatusCommitmentDetail.Text = "Onay İsteme Ekran metni girilmedi. Onay İsteme Ekran metnini girdikten sonra kaydetmeyi deneyiniz."
            Return
        End If

        If (txtConfirmCompleteSmsText.Value.Length = 0) Then
            checkSMSdata = False
            lblSMSStatusCommitmentDetail.Text = "Onay Tamamlanma SMS metni girilmedi. Onay Tamamlanma SMS metnini girdikten sonra kaydetmeyi deneyiniz."
            Return
        End If

        If (txtConfirmCompleteScreenText.Value.Length = 0) Then
            checkSMSdata = False
            lblSMSStatusCommitmentDetail.Text = "Onay Tamamlanma Ekran metni girilmedi. Onay Tamamlanma Ekran metnini girdikten sonra kaydetmeyi deneyiniz."
            Return
        End If

        If checkSMSdata Then

            Dim li As New ListItem

            smsConfirmRequestTextValue.Add(txtConfirmRequestSmsText.Value)
            screenConfirmRequestTextValue.Add(txtConfirmRequestScreenText.Value)
            smsConfirmCompleteTextValue.Add(txtConfirmCompleteSmsText.Value)
            screenConfirmCompleteTextValue.Add(txtConfirmCompleteScreenText.Value)
            li.Value = smsConfirmRequestTextValue.Count - 1

            li.Text = "<a href=# onclick=""showSmsPanel('openCommitmentDetailSmsPanel','" & li.Value & "-" & smsId & "')"">Taahhüt Detay SMS'leri</a>"

            If smsId = "thdAll" Then
                lnkbtnCommitmentDetailGeneral.Visible = False
                rblCommitmentDetailPGGeneral.Items.Add(li)
            End If
            If smsId = "thdPG1" Then
                lnkbtnCommitmentDetailPG1.Visible = False
                rblCommitmentDetailPG1.Items.Add(li)
            End If
            If smsId = "thdPG2" Then
                lnkbtnCommitmentDetailPG2.Visible = False
                rblCommitmentDetailPG2.Items.Add(li)
            End If
            If smsId = "thdPG3" Then
                lnkbtnCommitmentDetailPG3.Visible = False
                rblCommitmentDetailPG3.Items.Add(li)
            End If
            If smsId = "thdPG4" Then
                lnkbtnCommitmentDetailPG4.Visible = False
                rblCommitmentDetailPG4.Items.Add(li)
            End If
            If smsId = "thdPG5" Then
                lnkbtnCommitmentDetailPG5.Visible = False
                rblCommitmentDetailPG5.Items.Add(li)
            End If
            If smsId = "thdPG6" Then
                lnkbtnCommitmentDetailPG6.Visible = False
                rblCommitmentDetailPG6.Items.Add(li)
            End If

            trCommitmentDetailSmsArea.Visible = False
            lblCommitmentDetailSMSTitle.Text = String.Empty
            lblSMSStatusCommitmentDetail.Text = String.Empty
            txtConfirmRequestSmsText.Value = String.Empty
            txtConfirmRequestScreenText.Value = String.Empty
            txtConfirmCompleteSmsText.Value = String.Empty
            txtConfirmCompleteScreenText.Value = String.Empty
            divSaveSMSpanelCommitmentDetail.Visible = False
            divDeleteSMSpanelCommitmentDetail.Visible = False
            divConfirmDeletepanelCommitmentDetail.Visible = False
        End If

        lblPGGeneralCD.Visible = rblCommitmentDetailPGGeneral.Items.Count = 0
        lblPG1CD.Visible = rblCommitmentDetailPG1.Items.Count = 0
        lblPG2CD.Visible = rblCommitmentDetailPG2.Items.Count = 0
        lblPG3CD.Visible = rblCommitmentDetailPG3.Items.Count = 0
        lblPG4CD.Visible = rblCommitmentDetailPG4.Items.Count = 0
        lblPG5CD.Visible = rblCommitmentDetailPG5.Items.Count = 0
        lblPG6CD.Visible = rblCommitmentDetailPG6.Items.Count = 0
    End Sub

    Protected Sub btnCancelSaveCommitmentDetail_Click(sender As Object, e As EventArgs) Handles btnCancelSaveCommitmentDetail.Click
        trCommitmentDetailSmsArea.Visible = False
        lblCommitmentDetailSMSTitle.Text = String.Empty
        txtConfirmRequestSmsText.Value = String.Empty
        txtConfirmRequestScreenText.Value = String.Empty
        txtConfirmCompleteSmsText.Value = String.Empty
        txtConfirmCompleteScreenText.Value = String.Empty
        divSaveSMSpanelCommitmentDetail.Visible = False
        divDeleteSMSpanelCommitmentDetail.Visible = False
        divConfirmDeletepanelCommitmentDetail.Visible = False
    End Sub

    Protected Sub btnCancel2CommitmentDetail_Click(sender As Object, e As EventArgs) Handles btnCancel2CommitmentDetail.Click
        trCommitmentDetailSmsArea.Visible = False
        lblCommitmentDetailSMSTitle.Text = String.Empty
        txtConfirmRequestSmsText.Value = String.Empty
        txtConfirmRequestScreenText.Value = String.Empty
        txtConfirmCompleteSmsText.Value = String.Empty
        txtConfirmCompleteScreenText.Value = String.Empty
        divSaveSMSpanelCommitmentDetail.Visible = False
        divDeleteSMSpanelCommitmentDetail.Visible = False
        divConfirmDeletepanelCommitmentDetail.Visible = False
    End Sub

    Protected Sub btnCancelDeleteCommitmentDetail_Click(sender As Object, e As EventArgs) Handles btnCancelDeleteCommitmentDetail.Click
        trCommitmentDetailSmsArea.Visible = False
        lblCommitmentDetailSMSTitle.Text = String.Empty
        txtConfirmRequestSmsText.Value = String.Empty
        txtConfirmRequestScreenText.Value = String.Empty
        txtConfirmCompleteSmsText.Value = String.Empty
        txtConfirmCompleteScreenText.Value = String.Empty
        divSaveSMSpanelCommitmentDetail.Visible = False
        divDeleteSMSpanelCommitmentDetail.Visible = False
        divConfirmDeletepanelCommitmentDetail.Visible = False
    End Sub

    Protected Sub btnDeleteSMSCommitmentDetail_Click(sender As Object, e As EventArgs) Handles btnDeleteSMSCommitmentDetail.Click
        divSaveSMSpanelCommitmentDetail.Visible = False
        divDeleteSMSpanelCommitmentDetail.Visible = False
        divConfirmDeletepanelCommitmentDetail.Visible = True
    End Sub

    Private Sub removeCommitmentDetailItemFromRadioButtonList(ByVal rbl As RadioButtonList)
        Dim indexToDelete As Integer
        indexToDelete = rbl.Items.IndexOf(rbl.Items.FindByValue(smsRadioButtonValue.ToString))
        rbl.Items.RemoveAt(indexToDelete)

    End Sub

    Protected Sub btnConfirmDeleteCommitmentDetail_Click(sender As Object, e As EventArgs) Handles btnConfirmDeleteCommitmentDetail.Click
        If smsId = "thdAll" Then
            removeCommitmentDetailItemFromRadioButtonList(rblCommitmentDetailPGGeneral)
            lnkbtnCommitmentDetailGeneral.Visible = True
        End If
        If smsId = "thdPG1" Then
            removeCommitmentDetailItemFromRadioButtonList(rblCommitmentDetailPG1)
            lnkbtnCommitmentDetailPG1.Visible = True
        End If
        If smsId = "thdPG2" Then
            removeCommitmentDetailItemFromRadioButtonList(rblCommitmentDetailPG2)
            lnkbtnCommitmentDetailPG2.Visible = True
        End If
        If smsId = "thdPG3" Then
            removeCommitmentDetailItemFromRadioButtonList(rblCommitmentDetailPG3)
            lnkbtnCommitmentDetailPG3.Visible = True
        End If
        If smsId = "thdPG4" Then
            removeCommitmentDetailItemFromRadioButtonList(rblCommitmentDetailPG4)
            lnkbtnCommitmentDetailPG4.Visible = True
        End If
        If smsId = "thdPG5" Then
            removeCommitmentDetailItemFromRadioButtonList(rblCommitmentDetailPG5)
            lnkbtnCommitmentDetailPG5.Visible = True
        End If
        If smsId = "thdPG6" Then
            removeCommitmentDetailItemFromRadioButtonList(rblCommitmentDetailPG6)
            lnkbtnCommitmentDetailPG6.Visible = True
        End If

        trCommitmentDetailSmsArea.Visible = False
        lblCommitmentDetailSMSTitle.Text = String.Empty
        lblCommitmentDetailSMSTitle.Text = String.Empty
        txtConfirmRequestSmsText.Value = String.Empty
        txtConfirmRequestScreenText.Value = String.Empty
        txtConfirmCompleteSmsText.Value = String.Empty
        txtConfirmCompleteScreenText.Value = String.Empty
        divSaveSMSpanelCommitmentDetail.Visible = False
        divDeleteSMSpanelCommitmentDetail.Visible = False
        divConfirmDeletepanelCommitmentDetail.Visible = False


        lblPGGeneralCD.Visible = rblCommitmentDetailPGGeneral.Items.Count = 0
        lblPG1CD.Visible = rblCommitmentDetailPG1.Items.Count = 0
        lblPG2CD.Visible = rblCommitmentDetailPG2.Items.Count = 0
        lblPG3CD.Visible = rblCommitmentDetailPG3.Items.Count = 0
        lblPG4CD.Visible = rblCommitmentDetailPG4.Items.Count = 0
        lblPG5CD.Visible = rblCommitmentDetailPG5.Items.Count = 0
        lblPG6CD.Visible = rblCommitmentDetailPG6.Items.Count = 0
    End Sub
End Class